<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>{$_title}</h2>
    </div>
    <div class="form-horizontal" style="position: relative;">
        <div class="form-item">
            <label class="item-label">文件类型：<span class="check-tips">{$fileLimit.name}
            	<input type="hidden" name="file_type" id="file_type" value="{$fileLimit.type}"/>
            </span></label>
        </div>
        <div class="form-item">
            <label class="item-label">上传文件：<span class="check-tips"></span></label>
        </div>
	    <notempty name="file" >
	    	<input type="hidden" id="id" value="{$file.id}" />
	    	<div class="form-item">
            		<label class="item-label">文件名称：<span class="check-tips"><input type="text" class="text input-large" id="name" value="{$file.name|default=''}"></span></label>
        		</div>
	        <div class="form-item">
	            <label class="item-label">文件大小：<span class="check-tips">{$file.size_format|default=''}</span></label>
	        </div>
	        <div class="form-item">
	            <label class="item-label">文件类型：<span class="check-tips">{$file.ext|default=''}</span></label>
	        </div>
	        <notempty name="file['picture']">
		        <div class="form-item">
		            <label class="item-label">图片预览<span class="check-tips"></span></label>
		            <div class="controls">
		                <img src="/Fund/{$file.url}"/>
		            </div>
		        </div>
		    <else />
				<div class="form-item">
		            <label class="item-label">文件预览：<span class="check-tips"><a href="{$file.url|default=''}">查看文件</a></span></label>
		        </div>
	        </notempty>
	    </notempty>
	    
	    <div  style="position: absolute; top:35px; left:80px;">
	        <input type="file" class="text input-large" id="upload" value="">
    	</div>
	     <div class="form-item">
            	<notempty name="file">
	            	<button class="btn" style="margin-bottom:10px;" onclick="saveFile()">保存</button>
            	</notempty>
            	<button class="btn" style="margin-bottom:10px;" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
   </div>
</block>
<block name="style">
	<link href="__PUBLIC__/static/uploadify/uploadify.css" rel="stylesheet" media="screen">
</block>
<block name="script">
<script type="text/javascript" src="__PUBLIC__/static/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript">
    /* 初始化上传插件 */
	var option = {
		"swf"             : "__STATIC__/uploadify/uploadify.swf",
		"buttonText"      : "{$buttonText|default='上传文件'}",
		"uploader"        : "{:U('File/upload',array('session_id'=>session_id()))}",
		"fileTypeExts"	  : "{$fileLimit.ext}",
		"fileSizeLimit"	  : "{$fileLimit.size}",
		"onUploadStart":function(){
			var formData = $("#upload").uploadify("settings", "formData");
			formData['file_type'] = $("#file_type").val();
			formData['id'] = $("#id").val() ? $("#id").val() : '';
			formData['name'] = $("#name").val() ? $("#name").val() : '';
			$('#upload').uploadify('settings','formData',formData);
		},
		"onUploadSuccess" : function(file,data){
			var data = $.parseJSON(data);
			jsonDataDialog(data, {success:function(data){
				window.location.href = "{:U('File/fileList', array('file_type' => I('file_type')), true, true)}";
			}});
		},
	};

	//上传文件
	upload("#upload", {}, option);
    
	//修改文件信息
	function saveFile()
	{
		var param = {};
		param['id'] = $("#id").val();
		param['fileType'] = $("#file_type").val();
		param['name'] = $("#name").val();
		ajaxRequest('{:U("File/editFile")}', param, {'type':'post','func':function(data){
			jsonDataDialog(data);
		}});
	}
	
    //导航高亮
    highlight_subnav('{:U('File/fileList')}');
</script>
</block>
